//
// Created by xili on 2024/8/4 12:33.
// Go big or go home.
//
#include <vector>
#include <queue>

using namespace std;

class KthLargest {
public:
    priority_queue<int, vector<int>, greater<int>> q;
    int k;

    KthLargest(int k, vector<int> &nums) {
        this->k = k;
        for (auto &item: nums) {
            add(item);
        }
    }

    //维持k大小的优先级队列
    int add(int val) {
        q.push(val);
        if (q.size() > k) {
            q.pop();
        }
        return q.top();
    }
};

/**
 * Your KthLargest object will be instantiated and called as such:
 * KthLargest* obj = new KthLargest(k, nums);
 * int param_1 = obj->add(v);
 */